//
//  FxGetComment.m
//  TodayComment
//
//  Created by 张吉阳 on 15/9/12.
//  Copyright (c) 2015年 xianrenmoshi. All rights reserved.
//

#import "FxGetComment.h"
#import "CommentInfo.h"
#import "FxDBManager.h"
@implementation FxGetComment
- (void)parseData:(NSData *)data
{
    if (data.length <= 0) { //返回的长度为0，认为成功
        [self parseSuccess:nil jsonString:nil];
        return;
    }
    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dict = [FxJsonUtility jsonValueFromString:jsonString];
    [self parseSuccess:dict jsonString:jsonString];
    _receiveData = nil;
}

- (void)parseSuccess:(NSDictionary *)dict jsonString:jsonString
{
    if ([[dict valueForKey:@"code"]intValue] != 1 ) {
        [_delegate opSuccessMatch:dict];
    }
    else{
        if ([[dict valueForKey:@"hotPosts"] isEqual:[NSNull null]]) {
           [_delegate opSuccessEx:nil opinfo:dict];
        }
        else{
        [dict setValue:[_opInfo valueForKey:@"iconUrl"] forKeyPath:@"hotPosts.1.iconUrl"];
        [dict setValue:[_opInfo valueForKey:@"boardid"] forKeyPath:@"hotPosts.1.boardid"];
        NSArray *infos = [CommentInfo arrayFromDict:dict];
        [_delegate opSuccessEx:infos opinfo:dict];
        }
    }
 }

@end
